﻿''' <summary>
''' Contains code for Librarian functions.
''' </summary>
''' <author>Rick Simpson, Feng Jiang, AJ Whatling</author>
Partial Class pages_EditLibrary
    Inherits System.Web.UI.Page

    ''' <summary>
    ''' Adds a book ID for new books being added.  Without this, the server would throw 
    ''' an obscure error.
    ''' </summary>
    Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles BookDetailsView.ItemInserting
        ' Load up the largest ID.  The new ID will simply be this value incremented by one.
        ' A cheap but effective way to generate unique IDs.
        Dim GetLastIDSQL As String = "SELECT MAX(book_ID) FROM Books"
        Dim ResultReader As System.Data.OleDb.OleDbDataReader
        LibraryBookDataTier.Initialize()
        ResultReader = LibraryBookDataTier.ExecuteSelect(GetLastIDSQL)
        ResultReader.Read()

        e.Values("book_ID") = (CType(ResultReader(0).ToString, Integer) + 1).ToString

        LibraryBookDataTier.CloseDown()
    End Sub
End Class
